package com.aos.iot.socket.common.protocol;

import com.aos.iot.socket.common.message.Message;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class ProtocolFactor {

    private final Map<String, IProtocol> protocolMap;

    public ProtocolFactor(List<IProtocol> protocols) {
        this.protocolMap = protocols.stream().collect(Collectors.toMap(IProtocol::name, IProtocol::protocol));
    }

    public <M extends Message> IProtocol<M> getProtocol(String name) {
        return protocolMap.get(name);
    }

    public Map<String, IProtocol> getProtocolMap() {
        return protocolMap;
    }
}
